#ifndef QUICKSORT_H_INCLUDED
#define QUICKSORT_H_INCLUDED


int partition(int *vet, int l, int r) {
    int i = l; int j = r;
    int pivo = vet[l];
    while (true) {
    while ((j > i) && (vet[j] > pivo)) j--;
    if (i==j) break;
    vet[i] = vet[j]; i++;
    while ((i < j) && (vet[i] < pivo)) i++;
    if (i==j) break;
    vet[j] = vet[i]; j--;
    }
    vet[i] = pivo;
    return i;
}

void quicksort(int *vet, int l, int r) {
    if (r <= l) return;
    int pos = partition(vet, l, r);
    quicksort(vet, l, pos-1);
    quicksort(vet, pos+1, r);
}


#endif // QUICKSORT_H_INCLUDED
